﻿<div class="main">
    <form method="post" id="_form" class=" form form-lg form-group-sm" data-source="@Model">
        <div class="form-group" id="boxSelectUser">
            <label class="control-label">选择用户</label>
            <div class="controls">
                <select id="Uids" name="Uids" class="form-control ui-convertData multiple-select" multiple style="display:block;height:120px;" data-custom-params="url:'@Url.ActionUrl("LoadListByIds","Member")',textField:'Username'" data-validate="ignoreParentHidden:true,dataType:'*',nullMsg:'请选择要设置为管理员的用户！'"></select>
                <div class="btn-group btn-group-sm">
                    <a href="javascript:void(0)" class="btn btn-default btn-sm ui-dialog" data-custom-params="title:'选择用户',url:'@Url.ActionUrl("Select","Member")?objname=#Uids',width:'600px',height:'90%',target:'_self'">选择用户</a>
                    <a href="javascript:void(0)" class="btn btn-default btn-sm ui-removeSelectedOptions" title="按住Ctrl键可实现多选" data-custom-params="obj:'#Uids'">删除选中</a>
                </div>
                <span class="help-block">选择要设置为管理员的用户,支持同时添加多个管理员</span>
            </div>
        </div>

        <div class="form-group" id="boxUser">
            <label class="control-label">管理员用户</label>
            <div class="controls">
                <input type="text" name="Username" id="Username" readonly class="form-control" />
                <span class="help-block"></span>
            </div>
        </div>


        <div class="form-group">
            <label class="control-label">管理员角色</label>
            <div class="controls">
                <select class="form-control" id="RoleId" name="RoleId" data-source="@Html.GetRoleListJson()" data-validate="dataType:'*',nullMsg:'请选择管理角色！'">
                    <option value="">选择管理员角色</option>
                </select>
                <span class="help-block"></span>
            </div>
        </div>

        <div class="form-group">
            <label class="control-label">备注</label>
            <div class="controls">
                <input name="Remark" id="Remark" class="form-control" />
                <span class="help-block"></span>
            </div>
        </div>

        <div class="form-group">
            <label class="control-label">选择可管理的站点</label>
            <div class="controls">
                <select id="SiteIds" name="SiteIds" class="form-control ui-convertData multiple-select" multiple style="display:block;height:120px;" data-custom-params="url:'@Url.ActionUrl("LoadListByIds","Site")',textField:'Name'" data-source="@ViewBag.SiteIds"></select>
                <div class="btn-group btn-group-sm">
                    <a href="javascript:void(0)" class="btn btn-default btn-sm ui-dialog" data-custom-params="title:'选择站点',url:'@Url.ActionUrl("Select","Site")?objname=#SiteIds',width:'600px',height:'90%',target:'_self'">选择管理站点</a>
                    <a href="javascript:void(0)" class="btn btn-default btn-sm ui-removeSelectedOptions" title="按住Ctrl键可实现多选" data-custom-params="obj:'#SiteIds'">删除选中</a>
                </div>
                <span class="help-block">不选择则默认可以管理所有站点，超级管理员不受此设置限制。</span>
            </div>
        </div>


        <div class="form-group">
            <label class="control-label">选择默认管理的站点</label>
            <div class="controls form-inline">
                <div class="input-group">
                    <select id="DefaultSiteId" name="DefaultSiteId" class="form-control form-control-sm ui-convertData" data-custom-params="url:'@Url.ActionUrl("LoadListByIds","Site")',textField:'Name'" data-source="@ViewBag.DefaultSiteId" data-validate="dataType:'select',nullMsg:'请选择默认站点'"></select>
                    <span class="input-group-btn">
                        <a href="javascript:void(0)" class="btn btn-default btn-sm ui-dialog" data-custom-params="title:'选择站点',url:'@Url.ActionUrl("Select","Site")?objname=#DefaultSiteId',width:'600px',height:'90%',target:'self'">选择默认站点</a>
                    </span>
                </div>
                <span class="help-block">如果是非超级管理员，默认站点必须属于可管理的站点。</span>
            </div>
        </div>

        <div class="form-group">
            <label class="control-label">选择可管理的用户组</label>
            <div class="controls">
                <select id="MemberGroupIds" name="MemberGroupIds" class="form-control ui-convertData multiple-select" multiple style="display:block;height:120px;" data-custom-params="url:'@Url.ActionUrl("LoadListByIds","MemberGroup")',textField:'Name'" data-source="@ViewBag.MemberGroupIds"></select>
                <div class="btn-group btn-group-sm">
                    <a href="javascript:void(0)" class="btn btn-default btn-sm ui-dialog" data-custom-params="title:'选择用户组',url:'@Url.ActionUrl("Select","MemberGroup")?objname=#MemberGroupIds',width:'600px',height:'90%',target:'self'">选择用户组</a>
                    <a href="javascript:void(0)" class="btn btn-default btn-sm ui-removeSelectedOptions" title="按住Ctrl键可实现多选" data-custom-params="obj:'#MemberGroupIds'">删除选中</a>
                </div>
                <span class="help-block">不选择则默认可管理所有会员组，超级管理员不受此设置限制。</span>
            </div>
        </div>

        <div class="submit-footerbar">
            <label class="control-label"></label>
            <div class="controls">
                <input type="hidden" name="Uid" id="Uid" value="0" />
                <input type="hidden" name="Id" id="Id" value="0" />
                <button type="button" class="btn btn-sm btn-primary ui-pagePost" data-custom-params="url:'@Url.ActionUrl()',beforeExecute:'PostBeforeCheck',callBack:'PostRefreshBack'">提交</button>
                <button type="button" class="btn btn-sm btn-default ui-closeDialog">关闭</button>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript">
    //填充角色下拉
    var params = { valueField:'Id',textField:'Name',dataSourceFrom: "attr"};
    $("#RoleId").SelectBind(params);
    //绑定数据
    var id = Request("id");
    if (id != "") {
        $("#boxSelectUser").hide();
    }
    else
    {
        $("#boxUser").hide();
    }
    var id = Request("id");
    if (id != "") {
        $("#_form").FormBind({ dataSourceFrom: "attr" });
    }
    function PostBeforeCheck() {
        var hasExists = false;
        var $site_ids = $("#SiteIds");
        var $default_site_id = $("#DefaultSiteId");
        var default_site_id = $default_site_id.val();
        var $options = $site_ids.children("option");
        if (default_site_id == null) {
            Msg("请选择默认站点！");
            $default_site_id.focus();
            return false;
        }
        if ($options.length == 0) {
            return true;
        }
        $options.each(function () {
            var $this = $(this);
            if ($this.val() == default_site_id) {
                hasExists = true;
                return false;
            }
        });
        if (!hasExists) {
            Msg("默认站点必须包含在可管理的站点中！")
        }
        return hasExists;
    }
</script>

